package jrain.fw.http.common.pipeline;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import jrain.fw.http.common.handler.HttpHandler;
import jrain.fw.http.common.handler.error.ErrorHandler;
import jrain.fw.http.common.handler.rest.RestHandler;
import jrain.fw.http.common.handler.statics.StaticHandler;

/**
 * <pre>
 * 作者：3244924214@qq.com 
 * 描述：默认Http处理管道
 * </pre>
 */
public class DefaultHttpPipelineHandler implements HttpPipeline {

	private static final HttpHandler restHandler = new RestHandler();
	private static final HttpHandler staticHandler = new StaticHandler();
	private static final HttpHandler noHandler = new StaticHandler();
	private static final HttpHandler errorHandler = new ErrorHandler();

	@Override
	public void handler(HttpServletRequest request, HttpServletResponse response) {
		try {
			boolean b = restHandler.handler(request, response);
			if (!b) {
				b = staticHandler.handler(request, response);
			}
			if (!b) {
				noHandler.handler(request, response);
			}
		} catch (Exception e) {
			try {
				errorHandler.handler(request, response);
			} catch (Exception e1) {
				e1.printStackTrace();
			}
		}
	}

}
